package Fileutil;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

import cc.FileChooser;


public class fileInput {
	ArrayList<Employee> ar=new ArrayList<Employee>();
	public String getDateFromFile() {
		StringBuilder sb=new StringBuilder();
		String line=null;
		try {
			BufferedReader rd=new BufferedReader(new FileReader("employee.txt"));
			try {
				while((line=rd.readLine()) != null) {
					String[] arlist=line.split("\\|");
					Employee emp=new Employee(arlist[0],arlist[1],arlist[2],arlist[3], arlist[4]);
					ar.add(emp);
					sb.append(arlist[0]+" "+arlist[1]+" "+arlist[2]+" "+arlist[3]+" "+arlist[4]+"\n");
					
				}
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return sb.toString();
	}
	
	
	public String aaa(String st) {
		StringBuilder sb=new StringBuilder();
		for(Employee e:ar) {
			StringBuilder sb1=new StringBuilder();
			sb1.append(e.getName()+e.getDepartment()+e.getPhone()+e.getEmail()+e.getInstitution());
			if(sb1.toString().indexOf(st)!=-1) {
				sb.append(sb1+"\n");
			}
			
		}
		//System.out.println(sb.toString());
		return sb.toString();
	}
	
	public String wr(String wt,String sb) {
		FileChooser ff=new FileChooser();
		ff.lj();
		String f1="C:\\Users\\16536\\Desktop\\java程序设计\\sb.txt";
		String f=sb+".txt";
		System.out.println("15561561");
		try {
			FileWriter fw=new FileWriter(f);
			BufferedWriter bufw=new BufferedWriter(fw);
			bufw.write(wt);
			bufw.close();
			System.out.println("保存");
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return wt;
		
	}
	
	
	
	
	
	

}
